package com.yegs.jindie.quartz;

import com.yegs.jindie.JindieApplication;
import com.yegs.jindie.entity.PurchaseTO;
import com.yegs.jindie.service.PurchaseService;
import com.yegs.jindie.util.ExcelUtil;
import com.yegs.jindie.util.TxtUtil;
import org.quartz.DisallowConcurrentExecution;

import java.io.File;
import java.io.FileInputStream;
import java.util.Date;
import java.util.List;

@DisallowConcurrentExecution
public class PurchaseJob extends BaseJob{

    private PurchaseService purchaseService = (PurchaseService) JindieApplication.applicationContext.getBean("purchaseService");

    public String handle(Date beginDate, Date endDate,Integer int_last){
        try {
            String fileName = purchaseService.getFileName(endDate, int_last);
            List<PurchaseTO> list = purchaseService.getPutchase(beginDate, endDate);
            ExcelUtil.exporExcelByFtp(fileName, PurchaseTO.class, list);
            String path = TxtUtil.exporPurchaseTOTxt(fileName,list);
            FileInputStream fi = new FileInputStream(path);
            //super.upload(fi,path);
            return "执行成功";
        }catch (Exception e){
            e.printStackTrace();
            return e.getMessage();
        }
    }

}
